<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<meta name="decorator" content="sysDefault"
	content="text/html; charset=utf-8" />
	
	
<script type="text/javascript">

	var num = '${fn:length(list)}';
	var list = Array();
	
	window.onload = function(){
		for(var i=0; i<num; i++){
			list.push(i);
		}
	};
	
	
	function formSubmit(value) {
		document.all("form").setAttribute("action", value);
		document.all("form").submit();
	}

	function InsertRow() {
		//  动态添加行  
        var newRow = document.createElement ("tr");  
        //  动态创建列  
        var newTd0 = document.createElement ("td");     
        var newTd1 = document.createElement ("td");     
        var newTd2 = document.createElement ("td");     
        var newTd3 = document.createElement ("td");     
        //  动态添加内容  
        newTd0.innerHTML = '<span>参数名：<input type="text" value="" name="name" id="name'+num+'" '+
			'style="border: #7f9db9 1px solid; background: #FFFFFF; font-size: 12px; color: #333333; height: 20px; '+
				'line-height: 18px; width: 130px;" /></span>&nbsp;&nbsp;&nbsp;&nbsp;';

		newTd1.innerHTML = '<span>参数类型： <select id="type'+num+'">' + '<option value="0">int</option>'
				+ '<option value="1">long</option>'
				+ '<option value="2">float</option>'
				+ '<option value="3">String</option>'
				+ '<option value="4">blooean</option>' + '</select></span>&nbsp;&nbsp;&nbsp;&nbsp;';

		newTd2.innerHTML = '<span>参数值： <input type="text" value="" name="initParam" id="value'+num+'"'+
				'style="border: #7f9db9 1px solid; background: #FFFFFF;'+
				' font-size: 12px; color: #333333; height: 20px; line-height: 18px; width: 200px;" /></span>&nbsp;&nbsp;&nbsp;&nbsp;';

		newTd3.innerHTML = '<a href="javascript:void(0)" onclick="removeFile(this, this.parentElement.parentElement.rowIndex)">&nbsp;&nbsp;&nbsp;&nbsp;删除</a>';
   
        newRow.appendChild (newTd0);     
        newRow.appendChild (newTd1);
        newRow.appendChild (newTd2);
        newRow.appendChild (newTd3);     
        document.getElementById("tbody1").appendChild (newRow);
        list.push(num);
        num++;
	}
	
	function removeFile(id, index) {   
        var tr=id.parentNode.parentNode;  
        var tbody=tr.parentNode;  
        tbody.removeChild(tr); 
        list.splice(index, 1);
    } 

	function formSubmit(id){
		var jsonStr = "";
		jsonStr = "[";
		for(var i=0; i< list.length; i++){
			var name = document.getElementById("name"+list[i]).value;
			var type = document.getElementById("type"+list[i]).value;
			var value = document.getElementById("value"+list[i]).value;
			
			jsonStr += "{'name':'"+name+"', 'type':'"+type+"', 'value':'"+value+"'}";
			if(i != num-1){
				jsonStr +=",";
			}
		}
		jsonStr += "]";
		document.getElementById("paramForm").action = "${contextPath}/sys/quartz/param/addJobParameter?jsonStr="+jsonStr+"&job_id="+id;
		document.getElementById("paramForm").submit();
	}
	
	function disable(){
		var button = document.getElementById('addParam');
		if(num > 4){
			button.disabled=true;
		}else{
			button.disabled=false; 
		}
	}
	</script>
</head>
<body>	
	<div class="container-fluid">
		<div class="row">
			<div class="col-xs-12">
				<div class="panel panel-default">
					<div class="panel-heading">
						<h3 class="panel-title">
							新增定时任务 <a class="btn btn-default btn-sm pull-right"
								href="javascript:void(0)" onclick="history.go(-1)">返回</a>
						</h3>
					</div>
					<div class="panel-body">
					<form action="" method="post" id="paramForm">
						<tags:message content="${message}" />
							<table id="paramTab">
							 	<tbody id="tbody1">  
								<c:forEach var="parameter" items="${list }" varStatus="i"
									begin="0">
									<tr>
										<td  height="26" align="right" bgcolor="#FFFFFF"><span>参数名：<input
												type="text" name="name" id="name${i.index }"
												value="${parameter.name }"
												style="border: #7f9db9 1px solid; background: #FFFFFF; font-size: 12px; color: #333333; height: 20px; line-height: 18px; width: 130px;" />&nbsp;&nbsp;&nbsp;&nbsp;</span>
										</td>
										
										<td height="26" align="left" bgcolor="#FFFFFF"><span>参数类型：
												<select id="type${i.index }" name="type${i.index }">
													<option value="0"
														<c:if test="${parameter.type == 0 }">selected="selected"</c:if>>int</option>
													<option value="1"
														<c:if test="${parameter.type == 1 }">selected="selected"</c:if>>long</option>
													<option value="2"
														<c:if test="${parameter.type == 2 }">selected="selected"</c:if>>float</option>
													<option value="3"
														<c:if test="${parameter.type == 3 }">selected="selected"</c:if>>String</option>
													<option value="4"
														<c:if test="${parameter.type == 4 }">selected="selected"</c:if>>blooean</option>
											</select>
										</span>&nbsp;&nbsp;&nbsp;&nbsp;</td>
										
										<td height="26" align="left" bgcolor="#FFFFFF"><span>参数值：
												<input type="text" value="${parameter.value }" name="value0"
												id="value${i.index }"
												style="border: #7f9db9 1px solid; background: #FFFFFF; font-size: 12px; color: #333333; height: 20px; line-height: 18px; width: 200px;" />
										</span>&nbsp;&nbsp;&nbsp;&nbsp;</td>
										<td height="26" align="center" bgcolor="#FFFFFF">
											<a href="javascript:void(0)" onclick="removeFile(this,this.parentElement.parentElement.rowIndex)">&nbsp;&nbsp;&nbsp;&nbsp;删除</a>&nbsp;&nbsp;&nbsp;&nbsp;
										</td>
									</tr>
								</c:forEach>
								</tbody>
							</table>
						</form>
					</div>
					<div class="form-group" style="text-align: center; width: 600px;">
						<input class="btn btn-primary" type="button" value="添加参数"  id="addParam"
							onclick="InsertRow()" />
						 <input class="btn btn-primary"
							type="button" value="保存参数" onclick="formSubmit(${job_id})" />
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>